关于计时器[Visual Basic]

来源:百度知道 编辑:UC知道 时间:2024/05/13 07:59:59
关于计时器[Visual Basic]
我想样程序运行一个很大的运算(用For…next来做),并用Timer控件来计算运算的耗时(精确到毫秒),请问该如何做?
我在运算一开始把Timer开启,在到运算结束后关闭Timer,发现只计算到 0毫秒。
不行啊!!!???

在窗体中,加入TIMER控件,在程序的开头,设置一个字符变量,记录开始时的系统时间,在程序的结尾,设置一个字符变量,记录结束时间,再设置一个 Double变量,计算结束时间与开始时间的差即可.举例:
dim begin_time as string
begin_time=timer
......(此部分为程序主体部分)
dim end_time as string
end_time=timer
dim operator_time as Double
operator_time=cdbl(end_time)-cdbl(begin_time)
小数点前表示秒.

比如计算pi,那么在for之前加入
cotime=0
timer1.enabled = true,
for之后加入timer1.enabled=false
msgbox "用时:" & cotime
间隔为100(事先enabled=false)

声明:dim cotime as double
timer1_timer里面:

cotime=cotime+1